#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    _fileDialog = new QFileDialog(this, QString("Select file to load"), QString("."), QString("Images (*.png *.xpm *.jpg)"));

    QObject::connect(ui->actionLoad_image, SIGNAL(triggered()), _fileDialog, SLOT(exec()));
    QObject::connect(_fileDialog, SIGNAL(accepted()), this, SLOT(slot_loadImage()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slot_loadImage()
{
    QString fileName = _fileDialog->selectedFiles().at(0);

    qDebug() << "Load Image " << fileName;
    QImage img(fileName);
    ui->label->setPixmap(QPixmap::fromImage(img).scaled(ui->label->size(), Qt::KeepAspectRatio));

    emit signal_processImage(fileName);
}
